﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace HsTec.DigitalPlatform.DataAccess
{
    public class SpecInfoRepository
    {
        DigitalPlatformEntities db = new DigitalPlatformEntities();

        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="specinfo"></param>
        public void Add(SpecInfo specinfo)
        {
            db.AddToSpecInfos(specinfo);
            db.SaveChanges();
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="specinfo"></param>
        public void Delete(SpecInfo specinfo)
        {
            db.DeleteObject(specinfo);
            db.SaveChanges();
        }

        /// <summary>
        /// 保存
        /// </summary>
        public void Save()
        {
            db.SaveChanges();
        }

        /// <summary>
        /// 根据ID查询实体
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public SpecInfo GetSpecInfoByID(int id)
        {
            return db.SpecInfos.FirstOrDefault<SpecInfo>(d => d.speid == id);
        }

        /// <summary>
        /// 返回所有实体
        /// </summary>
        /// <returns></returns>
        public IQueryable<SpecInfo> FindALLSpecInfo()
        {
            return db.SpecInfos;
        }

        public IQueryable<ViSpecInfo> PageInfo(int page, int rp, string sortname, string sortorder)
        {
            return db.ViSpecInfos.OrderBy("it." + sortname + " " + sortorder).Skip((page - 1) * rp).Take(rp);
        }

        public int GetAllCount()
        {
            return db.SpecInfos.Count();
        }
    }
}
